﻿import QtQuick 2.0
import QtQuick.Controls 1.4
import QtQuick.Controls.Styles 1.4
import "../../js/UI.js" as Style
Rectangle {
    id: rect
    property alias m_headSource: m_head.m_source
    property alias p_pitch: pitch
    property alias m_name: m_NameText_id.text
    property alias m_sipSource: m_StatuImg_id.source
    property bool p_checkBoxChecked: false
    property bool p_checkBoxVisible: true
    property bool p_checkBoxEnable: true
    property bool serchmode: false;
    property var p_nameColor: "#323232"
    property alias a_sipImage: m_StatuImg_id
    property alias a_nameText: m_NameText_id
    property alias a_headImage: m_head
    signal clickSignal(var chose)
    color: "transparent"
    width: m_root_id.width
    height: m_lineValue*1.1

    CheckBox {
        id: pitch
        width: parent.height*0.4
        height: parent.height*0.4
        enabled: p_checkBoxEnable
        anchors.left: parent.left
        anchors.leftMargin: m_lineValue*0.4
        anchors.verticalCenter: parent.verticalCenter
        checked: p_checkBoxChecked
        visible: p_checkBoxVisible
        style: CheckBoxStyle {
            background: Image {
                sourceSize: Qt.size(0.4*m_lineValue,0.4*m_lineValue)
                source: !pitch.enabled?"qrc:/images/selected1.svg":
                                        pitch.checked ? "qrc:/images/duoxuanzhong.svg"
                                                      : "qrc:/images/duoxuanweizhong1.svg"
            }
            indicator: Item{}
        }
    }
    HeadImage {
        id: m_head
        width: parent.height*0.7
        height: width
        anchors.left: pitch.right
        anchors.leftMargin: m_lineValue*0.2
        anchors.verticalCenter: parent.verticalCenter
        nameText: m_NameText_id.text.substring(0,1)
        colorText:m_NameText_id.text.length>1?m_NameText_id.text.substring(1,2):""
    }

    Item {
        width: m_root_id.width - m_lineValue*2
        anchors.left: m_head.right
        anchors.leftMargin: m_lineValue*0.2
        height: parent.height*0.8
        anchors.verticalCenter: parent.verticalCenter
        AText {
            anchors.left: parent.left
            anchors.top: parent.top
            anchors.topMargin: (parent.height-paintedHeight)/2
            id: m_NameText_id
            width: parent.width
            font.pointSize: 16
            elide: Text.ElideRight
            wrapMode: Text.NoWrap
            color: p_nameColor
        }
    }
    Image{
        id: m_StatuImg_id
        width: m_lineValue*0.4
        anchors {
            right: parent.right
            rightMargin: m_lineValue*0.6
            verticalCenter: parent.verticalCenter
        }
        height: width
        fillMode: Image.PreserveAspectFit
    }
    MouseArea {
        id: mouseArea
        anchors.fill: parent
        onClicked: {
            p_checkBoxChecked = !p_checkBoxChecked
            if(p_checkBoxChecked)
                clickSignal(1)
            else
                clickSignal(-1)
        }
    }
    states: State {
        name: "pressed"; when: mouseArea.pressed
        PropertyChanges { target: rect ; color: Style.transparent_color;}
    }
    transitions: Transition {
        ColorAnimation { duration: 500 }
    }
}

